#!/bin/sh
source /etc/profile

# author @zenk
# mysqldump command position
mysqldump="/usr/local/mysql/bin/mysqldump"
# backup dir
backupdir="/usr/local/backup/"
# db host
dbhost="localhost"
# db port
dbport="3388"
# db user
dbuser="root"
# db pwd
dbpwd="1234"
# backup db name list
dbname="Dice Dice_admin Dice_apppay Dice_count Dice_friends Dice_gift Dice_offline Dice_pay"

#usage: now
#现在，包括日期和时间、纳秒
#比如：2010-02-27 11:29:52.991774000
cfile() {
  date "+%Y%m%d_%H%M"
}
filename="db$(cfile)"
sqlname="${filename}.sql"
tgzname="${filename}.tgz"

str="${mysqldump} -u${dbuser} -p${dbpwd} -h${dbhost} -P${dbport} --default-character-set=utf8 --disable-keys --opt --flush-logs --lock-tables --databases ${dbname} > ${backupdir}${sqlname}"

#执行备份数据库
echo ${str}|bash

#压缩导出的SQL文件
cd ${backupdir}
tar -zcf ${tgzname} ${sqlname}

#删除.sql文件
rm -f ${backupdir}${sqlname}
